package com.guangzhi.weijianzhi.company.center;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.guangzhi.weijianzhi.R;
import com.guangzhi.weijianzhi.activity.BaseActivity;
import com.guangzhi.weijianzhi.activity.MainPageActivity;
import com.guangzhi.weijianzhi.activity.UserAndCompanyActivity;
import com.guangzhi.weijianzhi.adapter.MyAddressadapterOne;
import com.guangzhi.weijianzhi.adapter.MyAddressadapterThree;
import com.guangzhi.weijianzhi.adapter.MyAddressadapterTwo;
import com.guangzhi.weijianzhi.adapter.MyArrayApterOne;
import com.guangzhi.weijianzhi.adapter.MyIndustryadapter;
import com.guangzhi.weijianzhi.adapter.MyIndustryadapterTwo;
import com.guangzhi.weijianzhi.context.WeiJianZhiEntity;
import com.guangzhi.weijianzhi.entity.BeansCity;
import com.guangzhi.weijianzhi.entity.BeansDistrict;
import com.guangzhi.weijianzhi.entity.BeansProvince;
import com.guangzhi.weijianzhi.http.HttpRequestUtils;
import com.guangzhi.weijianzhi.http.MyAsyncHttpResponseHandler;
import com.guangzhi.weijianzhi.utils.CommonUtils;
import com.guangzhi.weijianzhi.utils.Misc;
import com.guangzhi.weijianzhi.utils.PopuUtils;
import com.guangzhi.weijianzhi.utils.ProvinceCity;
import com.guangzhi.weijianzhi.view.IndustryData;
import com.guangzhi.weijianzhi.view.LodingFragmentDialog;
import com.guangzhi.weijianzhi.view.IndustryData.ProvinceAndCity;
import com.haarman.listviewanimations.swinginadapters.prepared.ScaleInAnimationAdapter;
/**
 * 公司注册界面
 * @author Administrator
 *
 */
public class CompileCompanyInfoActivity extends BaseActivity implements OnClickListener, OnCheckedChangeListener {
	private MyIndustryadapter adapterOne;
	private ListView one_list;
	private ListView two_list;
	private TextView mComType;
	private Set<String> keySet;
	private Map<String, List<ProvinceAndCity>> initData;
	private List<ProvinceAndCity> listC;
	private ArrayList<BeansProvince> privinces = null;
	private String hangye ="";
	private TextView mComScale;
	private TextView mComIndustry;
	private TextView mComAddress;
	
	private ListView addreTwo_list;
	private ListView addreThree_list;
	private ListView addressOne_list;
	private String name="";
	private String Cityname="";
	private ArrayList<BeansCity> citys;
	private MyAddressadapterTwo MyAddressadapterTwo ;
	private ArrayList<BeansDistrict> districts;
	private Button mCom_save;
	private TextView mComName;
	private TextView mComAddressAdd;
	private TextView mComIntro;
	private EditText mInfoName;
	private EditText mInfoNumber;
	private PopupWindow mPop;
	private File outputimage =null;
	private ArrayList<String> imagelist = new ArrayList<String>();// 图片路径集合
	private ArrayList<String> imagenameList = new ArrayList<String>();
	private ArrayList<BitmapDrawable> imags = new ArrayList<BitmapDrawable>();
	
	private Uri imageUri;
	private Bitmap b;;// 图片名字集合
	
	private String areaCode ="";//地区码；
	private String industryCode ="";//地区码；
	private ImageView delete_one,delete_two,delete_three;
	private String typeCode="";
	private String scaleCode="";
	private LinearLayout mLin_image;
	private RadioButton title_right;
	private ImageView mOpenImaage;
	private boolean isSelect;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tz_company_info_layout);
		isSelect = getIntent().getBooleanExtra("select", false);
		 initData = IndustryData.initData(getResources());
		 privinces = ProvinceCity.initData(CompileCompanyInfoActivity.this);
		 keySet = initData.keySet();
		initView();
		initData();
	}

	private void initData() {
		HttpRequestUtils.doHttpSubComData(WeiJianZhiEntity.access_token, new MyAsyncHttpResponseHandler(getSupportFragmentManager(),getResources()) {
			@Override
			public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
				// TODO Auto-generated method stub
				super.onSuccess(arg0, arg1, arg2);
				
				try {
					JSONObject jsonO = new JSONObject(new String(arg2));
					if(jsonO.optBoolean("status")){
						JSONArray optJSONArray = jsonO.optJSONArray("data");
						if(optJSONArray.length()!=0){
							JSONObject optJSONObject = optJSONArray.optJSONObject(0);
							mComName.setText(optJSONObject.optString("company_name"));
							mComIndustry.setText(optJSONObject.optString("vocationString"));
							String vocation =optJSONObject.optString("vocation");
							String[] split = vocation.split("\\|");
							industryCode =split[split.length-1];
							mComScale.setText(getScale(optJSONObject.optString("scale")));
							scaleCode =optJSONObject.optString("scale");
							mInfoName.setText(optJSONObject.optString("contacts_name"));
							mInfoNumber.setText(optJSONObject.optString("contacts_tel"));
							mComAddress.setText(optJSONObject.optString("areaString"));
							areaCode =optJSONObject.optString("area");
							mComAddressAdd.setText(optJSONObject.optString("full_address"));
							mComIntro.setText(optJSONObject.optString("intro"));
							mComType.setText(getType(optJSONObject.optString("type")));
							typeCode =optJSONObject.optString("type");
							if(Misc.notNull(optJSONObject.optString("picurl"))){
								parserUrl(optJSONObject.optString("picurl"));
							}
							title_right.setChecked(false);
						}else{
							Misc.alert("您还没有注册公司信息");
							title_right.setVisibility(View.GONE);
						}
					}else{
						Misc.alert(jsonO.optString("errMessage"));
					}
					
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			
			private void parserUrl(String optString) {
				// TODO Auto-generated method stub
				if(optString.contains("|")){
					String[] split = optString.split("\\|");
					
					for(int j=0;j<split.length;j++){
						  View view =View.inflate(CompileCompanyInfoActivity.this,R.layout.tz_image_delete_layout, null);
						 ImageView iv = (ImageView) view.findViewById(R.id.image);
						 if(j==0){delete_one = (ImageView) view.findViewById(R.id.delete_image);}
						 if(j==1){delete_two = (ImageView) view.findViewById(R.id.delete_image);}
						 if(j==2){delete_three = (ImageView) view.findViewById(R.id.delete_image);}
						 mLin_image.addView(view);
						 CommonUtils.showImage(split[j], iv,imags);
						 view.setId(j);
						 imagelist.add(Environment.getExternalStorageDirectory().getPath()+"/"+split[j]);
						 imagenameList.add(split[j]);
						 view.setOnClickListener(CompileCompanyInfoActivity.this);
					}
				}else{
					 View view =View.inflate(CompileCompanyInfoActivity.this,R.layout.tz_image_delete_layout, null);
					 ImageView iv = (ImageView) view.findViewById(R.id.image);
					 delete_one = (ImageView) view.findViewById(R.id.delete_image);
					 mLin_image.addView(view);
					 CommonUtils.showImage(optString, iv,imags);
					 view.setId(0);
					 imagelist.add(Environment.getExternalStorageDirectory().getPath()+"/"+optString);
					 imagenameList.add(optString);
					 view.setOnClickListener(CompileCompanyInfoActivity.this);
				}
			}

			@Override
			public void onFailure(int arg0, Header[] arg1, byte[] arg2,
					Throwable arg3) {
				// TODO Auto-generated method stub
				super.onFailure(arg0, arg1, arg2, arg3);
			}
			
			@Override
			public void onFinish() {
				// TODO Auto-generated method stub
				super.onFinish();
				LodingFragmentDialog.dismiss(getSupportFragmentManager());
			}
		});
		
	}

	private void initView() {
		// TODO Auto-generated method stub
		findViewById(R.id.title_back).setOnClickListener(this);
		TextView title_tv = (TextView) findViewById(R.id.title_lable);
		title_tv.setText("公司详情");
		title_right = (RadioButton) findViewById(R.id.title_radio);
		title_right.setOnCheckedChangeListener(this);
		
		mOpenImaage = (ImageView) findViewById(R.id.com_open);
		mOpenImaage.setOnClickListener(this);
		mComName = (TextView) findViewById(R.id.com_name);
		mComIndustry = (TextView) findViewById(R.id.com_industry);//所属行业
		mComType = (TextView) findViewById(R.id.com_type);//公司类型
		mComScale = (TextView) findViewById(R.id.com_scale);//公司规模
		mLin_image = (LinearLayout) findViewById(R.id.lin_image);//用来添加
		
		mComAddress = (TextView) findViewById(R.id.com_address);//地址
		mComAddressAdd = (TextView) findViewById(R.id.com_detailedadd);
		mComIntro = (TextView) findViewById(R.id.com_intro);
		
		mInfoName = (EditText) findViewById(R.id.info_name);
		mInfoNumber = (EditText) findViewById(R.id.info_number);
		mCom_save = (Button) findViewById(R.id.com_save);
		
		
		mComName.setOnClickListener(this);
		mComAddress.setOnClickListener(this);
		mComIntro.setOnClickListener(this);
		
		mComScale.setOnClickListener(this);
		mComType.setOnClickListener(this);
		mComIndustry.setOnClickListener(this);
		mComAddressAdd.setOnClickListener(this);
		mCom_save.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.com_name:
			Intent intent = new Intent(this, EdittextActivity.class);
		   intent.putExtra("name","1");
			 startActivityForResult(intent,1);
			break;
		case R.id.com_detailedadd:
			Intent intent2 = new Intent(this, EdittextActivity.class);
			 intent2.putExtra("name","2");
			 startActivityForResult(intent2,2);
			break;
		case R.id.com_intro:
			Intent intent3 = new Intent(this, EdittextActivity.class);
			 intent3.putExtra("name","3");
			 startActivityForResult(intent3,3);
			break;
		case R.id.com_type://公司类型
			showType();
			break;
		case R.id.com_industry://公司行业
			showIndustry();
			break;
		case R.id.com_address://地址
			showAddress();
			
			break;
		case 0://
			if(delete_one!=null && delete_one.getVisibility() ==View.VISIBLE)
			OnclickLin(0);
			
			break;
		case 1://
			if(delete_two!=null && delete_two.getVisibility() ==View.VISIBLE)
			OnclickLin(1);
			
			break;
		case 2://
			if(delete_three!=null && delete_three.getVisibility() ==View.VISIBLE)
			OnclickLin(2);
			
			break;
		case R.id.com_scale://公司规模
			showScale();
			break;
		case R.id.com_save://保存按钮
			if(isOk()){
				String pic ="";
				for(int i =0;i<imagenameList.size();i++){
					if(i!=imagenameList.size()-1){
						pic+=imagenameList.get(i)+"|";
					}else{
						pic+=imagenameList.get(i);
					}
				}
				CommonUtils.submitImages(CompileCompanyInfoActivity.this, imagelist, imagenameList);
				submitCompanyData(pic);
			}
			break;
		case R.id.com_open:
			if(imagelist.size()<3){
				showOpen();
			}else{
				Misc.alert("最多上传三张照片");
			}
			break;
		case R.id.camera:
			Misc.alert("打开相机");
			mPop.dismiss();
			openCamera();
			break;
		case R.id.photo:
			Misc.alert("打开相册");
			takePhotosFromLocal();
			mPop.dismiss();
			break;
		case R.id.cancel:
			mPop.dismiss();
			break;
		}
	}
	private void OnclickLin(int i) {
		// TODO Auto-generated method stub
		imagelist.remove(i);imagenameList.remove(i); imags.remove(i);
		
		if(mLin_image!=null){
			mLin_image.removeAllViews();
			for(int j=0;j<imags.size();j++){
				 final View view =View.inflate(CompileCompanyInfoActivity.this,R.layout.tz_image_delete_layout, null);
				 if(j==0){delete_one = (ImageView) view.findViewById(R.id.delete_image);}
				 if(j==1){delete_two = (ImageView) view.findViewById(R.id.delete_image);}
				 if(j==2){delete_three = (ImageView) view.findViewById(R.id.delete_image);}
				 
				 ImageView iv = (ImageView) view.findViewById(R.id.image);
				 mLin_image.addView(view);
				 iv.setBackgroundDrawable(imags.get(j));
				 view.setId(j);
				 view.setOnClickListener(CompileCompanyInfoActivity.this);
			}
		}
	}

	private void submitCompanyData(String picurl) {
		// TODO Auto-generated method stub
		HttpRequestUtils.doHttpSubComData(WeiJianZhiEntity.access_token,
				mComName.getText().toString(), typeCode, industryCode,
				scaleCode, mInfoName.getText().toString(), mInfoNumber.getText().toString(), 
				areaCode, mComAddressAdd.getText().toString(),
				mComIntro.getText().toString(), picurl, 
				new MyAsyncHttpResponseHandler(getSupportFragmentManager(),getResources()) {
			         
			      @Override
			    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
			    	// TODO Auto-generated method stub
			    	super.onSuccess(arg0, arg1, arg2);
			    	try {//{"data":[{"result":"保存成功!"}],"errMessage":"","status":true}
						JSONObject jsonO = new JSONObject(new String(arg2));
						
						if(jsonO.optBoolean("status")){
							JSONArray optJSONArray = jsonO.optJSONArray("data");
							if(optJSONArray.length()!=0){
								JSONObject optJSONObject = optJSONArray.optJSONObject(0);
								String result = optJSONObject.optString("result");
								if(isSelect){//如果是从身份选择页面进来
									WeiJianZhiEntity.isLogin =1;
									startActivity(new Intent(CompileCompanyInfoActivity.this, MainPageActivity.class));
								}else{
									finish();
								}
								Misc.alert(result);
							}
						}else{
							Misc.alert(jsonO.optString("errMessage"));
						}
						
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			    	
			    }
			      @Override
			    	public void onFinish() {
			    		// TODO Auto-generated method stub
			    		super.onFinish();
			    		LodingFragmentDialog.dismiss(getSupportFragmentManager());
			    	}
			      
				});
	}

	private void openCamera() {
		if (outputimage!=null && outputimage.exists()) {
			outputimage.delete();
		}
		outputimage  = Misc.createFile();
		imageUri = Uri.fromFile(outputimage);
		
		
		
        Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // 指定调用相机拍照后照片的储存路径
        cameraintent.putExtra(MediaStore.EXTRA_OUTPUT,
        		imageUri);
		startActivityForResult(cameraintent, 8);
	}
	
	/**
	 * 从本地相册获取
	 */
	private void takePhotosFromLocal() {
		try {
			if (outputimage!=null&&outputimage.exists()) {
				outputimage.delete();
			}
			outputimage  = Misc.createFile();
		} catch (Exception e) {
			e.printStackTrace();
		}
		Intent intent = new Intent();
		intent.setType("image/*");
		intent.setAction(Intent.ACTION_GET_CONTENT);
		startActivityForResult(intent, 10);
	}
	private void showOpen() {
		// TODO Auto-generated method stub
		View inflate = View.inflate(this, R.layout.tz_photo_camera_layout, null);
		mPop = PopuUtils.showPou(View.inflate(this, R.layout.main_activity_layout, null),inflate, this, this);
		inflate.findViewById(R.id.camera).setOnClickListener(this);
		inflate.findViewById(R.id.photo).setOnClickListener(this);
		inflate.findViewById(R.id.cancel).setOnClickListener(this);
	}

	public boolean isOk(){
		
		if(!Misc.notNull(mComName.getText().toString())){
			Misc.alert("公司名称4-18字");
			return false;
		}
		if(!Misc.notNull(mComIndustry.getText().toString())){
			Misc.alert("请选择公司所属行业");
			return false;
		}
		if(!Misc.notNull(mComType.getText().toString())){
			Misc.alert("请选择公司类型");
			return false;
		}
		if(!Misc.notNull(mComScale.getText().toString())){
			Misc.alert("请选择公司规模");
			return false;
		}
		
		if(!Misc.notNull(mComAddress.getText().toString())){
			Misc.alert("请选择公司地址");
			return false;
		}
		
		if(!Misc.notNull(mComAddressAdd.getText().toString())){
			Misc.alert("请输入公司详细地址");
			return false;
		}
		if(!Misc.notNull(mComIntro.getText().toString())){
			Misc.alert("请输入公司简介");
			return false;
		}
		
		if(!Misc.notNull(mInfoName.getText().toString())){
			Misc.alert("请输入联系人姓名");
			return false;
		}
		if(!Misc.notNull(mInfoName.getText().toString())){
			Misc.alert("请输入联系人电话");
			return false;
		}
		
		return true;
	}
	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		// TODO Auto-generated method stub
		super.onActivityResult(arg0, arg1, arg2);
		if(arg1==RESULT_OK){
			
			switch (arg0) {
			case 8:
				try {
					String a1 = CommonUtils.getThumbUploadPath(
							CompileCompanyInfoActivity.this, outputimage.toString(),
							280, imageUri, outputimage, imagenameList);
					imagelist.add(a1);
					BitmapFactory.Options options = new BitmapFactory.Options();
					options.inSampleSize = 2;// 图片宽高都为原来的二分之一，即图片为原来的四分之一
					b = BitmapFactory.decodeFile(a1, options);
					BitmapDrawable bd = new BitmapDrawable(b);
					
					 View view =View.inflate(CompileCompanyInfoActivity.this,R.layout.tz_image_delete_layout, null);
					 ImageView iv = (ImageView) view.findViewById(R.id.image);
					 iv.setBackgroundDrawable(bd);
					 mLin_image.addView(view);
					 view.setId(imags.size());
					 imags.add(bd);
					 view.setOnClickListener(CompileCompanyInfoActivity.this);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
				break;

			case 10:
				if(arg1 ==RESULT_OK){
					try {
					Uri uri = arg2.getData();
					if(uri!=null){
						String realPath = CommonUtils.getRealPathFromURI(
								CompileCompanyInfoActivity.this, uri);
						
						String a1= CommonUtils.getThumbUploadPath(
									CompileCompanyInfoActivity.this, realPath, 280, uri,
									outputimage, imagenameList);
						
						
						imagelist.add(a1);
						
						/** 以下为显示图片 **/
						BitmapFactory.Options options = new BitmapFactory.Options();
						options.inSampleSize = 2;// 图片宽高都为原来的二分之一，即图片为原来的四分之一
						b = BitmapFactory.decodeFile(a1, options);
						BitmapDrawable bd = new BitmapDrawable(b);
						
						 View view =View.inflate(CompileCompanyInfoActivity.this,R.layout.tz_image_delete_layout, null);
						 ImageView iv = (ImageView) view.findViewById(R.id.image);
						 iv.setBackgroundDrawable(bd);
						 mLin_image.addView(view);
						 view.setId(imags.size());
						 imags.add(bd);
						 view.setOnClickListener(CompileCompanyInfoActivity.this);
						
					}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				break;
			case 1:
				mComName.setText(arg2.getStringExtra("resust"));
				break;
			case 2:
				mComAddressAdd.setText(arg2.getStringExtra("resust"));
				break;
			case 3:
				mComIntro.setText(arg2.getStringExtra("resust"));
				break;
			}
			
			
		}
		
	}
	
	
     /**
      * 城市三级
      */
	private void showAddress() {
		// TODO Auto-generated method stub
		 View view	=View.inflate(this, R.layout.tz_three_listview_layout, null);
		 final PopupWindow window = new PopupWindow(view, LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,true);
			PopuUtils.addAttriBute(window);
			window.showAtLocation(View.inflate(this, R.layout.tz_company_info_layout,null), Gravity.BOTTOM, 0, 0);
			PopuUtils.changeActivity(CompileCompanyInfoActivity.this);
			PopuUtils.changeActivity(window,CompileCompanyInfoActivity.this);
		 
		 
			addressOne_list = (ListView)view. findViewById(R.id.one_list);
			final MyAddressadapterOne MyAddressadapterOne = new MyAddressadapterOne(privinces,CompileCompanyInfoActivity.this);
			addressOne_list.setAdapter(Misc.getMyadapter(MyAddressadapterOne, addressOne_list));
			addressOne_list.setOnItemClickListener(new OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					// TODO Auto-generated method stub
					MyAddressadapterOne.isSelect(position);
					citys = privinces.get(position).getCitys();
					MyAddressadapterTwo = new MyAddressadapterTwo(citys,CompileCompanyInfoActivity.this);
					name  = privinces.get(position).getName();
					addreTwo_list.setAdapter(Misc.getMyadapter(MyAddressadapterTwo, addreTwo_list));
					
					if(addreThree_list.getVisibility()==View.VISIBLE){
						addreThree_list.setVisibility(View.GONE);
					}
					
				}
			});
			addreTwo_list = (ListView) view.findViewById(R.id.two_list);
			addreThree_list = (ListView) view.findViewById(R.id.three_list);
			addreTwo_list.setOnItemClickListener(new OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					// TODO Auto-generated method stub
					MyAddressadapterTwo.isSelect(position);
					  districts = citys.get(position).getDistricts();
					  Cityname =  citys.get(position).getName();
					 addreThree_list.setAdapter(Misc.getMyadapter(new MyAddressadapterThree(districts,CompileCompanyInfoActivity.this), addreThree_list));
					 if(addreThree_list.getVisibility()==View.GONE){
						 addreThree_list.setVisibility(View.VISIBLE);
					 }
				}
			});
			addreThree_list.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					// TODO Auto-generated method stub
					String str ="";
					BeansDistrict beansDistrict = districts.get(position);
					
					if(name.equals(Cityname)){
						str =name+"/"+beansDistrict.getName();
					}else{
						
						str =name+"/"+Cityname+"/"+beansDistrict.getName();
					}
					areaCode =beansDistrict.getId();
			//		String id_name = beansDistrict.getId()+"|"+str;
					mComAddress.setText(str);
					window.dismiss();
				}
			});
	}

	private void showScale() {
		final ArrayList<String> lists = new ArrayList<String>();
		lists.add("20人以下");
		lists.add("20~99人");
		lists.add("100~499人");
		lists.add("500~999人");
		lists.add("1000~9999人");
		lists.add("10000人以上");
		// TODO Auto-generated method stub
		View view = View.inflate(this, R.layout.tz_pop_list_layout, null);
		ListView list = (ListView) view.findViewById(R.id.one_list);
		final PopupWindow showPou = PopuUtils.showPou(View.inflate(this, R.layout.tz_company_info_layout, null), view, this, this);
		MyArrayApterOne array = new MyArrayApterOne(lists, this);
		list.setAdapter(Misc.getMyadapter(array, list));
		list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
	          	 mComScale.setText(lists.get(arg2));
            	 scaleCode =(++arg2)+"";
            	 showPou.dismiss();
			}
		});
	}

	/**
	 * 行业两级
	 */
	private void showIndustry() {
		// TODO Auto-generated method stub
	  View view =View.inflate(this, R.layout.inin_dowlist_layout, null);
	  one_list = (ListView) view.findViewById(R.id.one_list);
	 two_list = (ListView) view.findViewById(R.id.two_list);
		final PopupWindow window = new PopupWindow(view, LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,true);
		PopuUtils.addAttriBute(window);
		window.showAtLocation(View.inflate(this, R.layout.tz_company_info_layout,null), Gravity.BOTTOM, 0, 0);
		PopuUtils.changeActivity(CompileCompanyInfoActivity.this);
		PopuUtils.changeActivity(window,CompileCompanyInfoActivity.this);
		
		   final List<String> texts = new ArrayList<String>(keySet);
	       adapterOne = new MyIndustryadapter(texts,CompileCompanyInfoActivity.this);
			one_list.setAdapter(Misc.getMyadapter(adapterOne, one_list));
	       
	        one_list.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				 new MyIndustryadapter(texts,CompileCompanyInfoActivity.this);
				adapterOne.seletePosition(position);
				String string = ((TextView)view).getText().toString();
				hangye = "";
				hangye = string+"/";
				listC = initData.get(string);
				MyIndustryadapterTwo mAdapterTwo = new MyIndustryadapterTwo(listC,CompileCompanyInfoActivity.this);
				two_list.setAdapter(Misc.getMyadapter(mAdapterTwo, two_list));
			}
		});
	   
	   two_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int positi, long id) {
				// TODO Auto-generated method stub
				ProvinceAndCity provinceAndCity = listC.get(positi);
				String string = ((TextView)view).getText().toString();
				industryCode = provinceAndCity.id;
				mComIndustry.setText(string);
				window.dismiss();
			}
		});
	   
	}

	private void showType() {
		
		
		final ArrayList<String> lists = new ArrayList<String>();
		lists.add("国企");
		lists.add("民营");
		lists.add("合资");
		lists.add("外商独资");
		lists.add("上市公司");
		lists.add("政府单位");
		View view = View.inflate(this, R.layout.tz_pop_list_layout, null);
		ListView list = (ListView) view.findViewById(R.id.one_list);
		final PopupWindow showPou = PopuUtils.showPou(View.inflate(this, R.layout.tz_company_info_layout, null), view, this, this);
		MyArrayApterOne array = new MyArrayApterOne(lists, this);
		list.setAdapter(Misc.getMyadapter(array, list));
		list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				mComType.setText(lists.get(arg2));
				typeCode =(++arg2)+"";
				showPou.dismiss();
			}
		});
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if(b!=null&&b.isRecycled()){
			b.recycle();
		}
		
	}
	
	public String getScale(String str){
		String scale="";
		switch (Integer.parseInt(str)) {
		case 1:
			scale ="20人以下";
			break;
		case 2:
			scale =" 20~99人";
			break;
		case 3:
			scale ="100~499人";
			break;
		case 4:
			scale ="500~999人";
			break;
		case 5:
			scale ="1000~9999人";
			break;
		case 6:
			scale ="10000人以上";
			break;
		}
		return scale;
	}
	public String getType(String str){
		String type="";
		switch (Integer.parseInt(str)) {
		case 1:
			type =" 国企";
			break;
		case 2:
			type ="民营";
			break;
		case 3:
			type ="合资";
			break;
		case 4:
			type ="外商独资";
			break;
		case 5:
			type ="上市公司";
			break;
		case 6:
			type ="政府单位";
			break;
			
		}
		return type;
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub
		isCheck(isChecked);
		
	}
	public void isCheck(boolean check){
		mComName.setClickable(check);
		mComIndustry.setClickable(check);
		mComType.setClickable(check);
		mComScale.setClickable(check);
		
		mComAddress.setClickable(check);
		mComAddressAdd.setClickable(check);//
		mComIntro.setClickable(check);
		
		mInfoName.setClickable(check);mInfoName.setEnabled(check);
		mInfoNumber.setClickable(check);mInfoNumber.setEnabled(check);
		if(check){
			title_right.setText("编辑中");
			mCom_save.setVisibility(View.VISIBLE);
			if(delete_one!=null)delete_one.setVisibility(View.VISIBLE);
			if(delete_two!=null)delete_two.setVisibility(View.VISIBLE);
			if(delete_three!=null)delete_three.setVisibility(View.VISIBLE);
			mOpenImaage.setClickable(check);
		}else{
			title_right.setText("编辑");
			if(delete_one!=null)delete_one.setVisibility(View.GONE);
			if(delete_two!=null)delete_two.setVisibility(View.GONE);
			if(delete_three!=null)delete_three.setVisibility(View.GONE);
			mCom_save.setVisibility(View.GONE);
			mOpenImaage.setClickable(check);
		}
		
	}
}

































































